package com.proxy.autoclick.queue;

import java.util.Date;
import java.util.concurrent.BlockingQueue;
import java.util.Random;
import java.io.PrintStream;

public class Producer extends Thread
{
  private BlockingQueue<String> blockingQueue;
  private PrintStream printStream;

  public Producer(BlockingQueue<String> blockingQueue, PrintStream printStream)
  {
    this.printStream = printStream;
    this.blockingQueue = blockingQueue;
  }

  public void run()
  {
    try
    {
      while(true)
      {
        String time = String.format("%tc",new Date());
        printStream.println("Putting item on BlockingQueue at time: " + time);
        blockingQueue.put("Enqueued at: " + time);
        Random generator = new Random();
        int randomSleep = generator.nextInt(5) + 1;
        Thread.sleep(randomSleep * 1000);
      }
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
  }
}
